/-app
/-core ...
Long.ts
async.ts
format.ts
/-headers
/-imports
/-io
/-managed
/-typings
/-unmanaged
pe.html
pe.ts
1
module pe {
2
 
3
  /**
4
   *
5
   */
6
  export interface AsyncCallback<T> {
7
    completed(result: T);
8
    failed(error: Error);
9
 
10
    progress?: AsyncProgress;
11
  }
12
 
13
  export interface AsyncProgress {
14
    progress(value: number, total: number): boolean;
15
    continueLater(next: () => void);
16
  }
17
 
18
  export class DefaultAsyncProgress implements AsyncProgress {
19
 
20
    yieldAfter: number;
21
    yieldInterval = 200;
22
 
23
    constructor() {
24
      this.yieldAfter = this.now() + this.yieldInterval;
25
    }
26
 
27
    progress(value: number, total: number): boolean {
28
      var now = this.now();
29
      return now > this.yieldAfter;
30
    }
31
 
32
    continueLater(next: () => void) {
33
      setTimeout(next, this.yieldInterval);
34
    }
35
 
36
    now(): number {
37
      return Date.now();
38
    }
39
 
40
  }
41
 
42
}